package planner.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.mysql.jdbc.StringUtils;

public class LogoutController extends AbstractController {
	private String redirectUrl = null;
	public void setRedirectUrl(String redirectUrl) {
		this.redirectUrl = redirectUrl;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		HttpSession session = request.getSession();
		session.removeAttribute("userSession");
		session.invalidate();
		
		if(StringUtils.isNullOrEmpty(redirectUrl)){
			redirectUrl = "/login.plan";
		}
		return new ModelAndView("redirect:" + redirectUrl);
	}

}
